package xfuzzy.alg_genetico.test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;

import xfuzzy.alg_genetico.doble_cromosoma.algorithm.ResultGA;
import xfuzzy.alg_genetico.doble_cromosoma.codification.DoubleChromosome;
import xfuzzy.alg_genetico.doble_cromosoma.evaluation.EvaluationXfuzzy;
import xfuzzy.alg_genetico.doble_cromosoma.finalversion.XfghlConfig;
import xfuzzy.xfhl.model.XfhlData;
import xfuzzy.xfhl.model.spec.XfhlInputType;
import xfuzzy.xfhl.model.spec.XfhlOperSet;

public class GeneradorPasosConfiguraciones {

	public static void main(String[] args) {

		System.out.println("inicio");
		File fileDataSet = new File ("/home/max/workspace/xfuzzy/examples/regression/fun7/fun7.dat");
		//File fileDataSet = new File("fun7.dat");
 		String fuzzysystem = "noname_000.xfl";
 		String nameSystem = fuzzysystem;
	    int numIterAjus = 40;
 		//int numIterAjus = 1;
	    int numThreads = 1;

	    double iniUpd = 0.1;
	    double incFact = 1.5;
	    double decFact = 0.7;
	    int mfs = 3;
	    int operatorAND = XfhlOperSet.AndOperatorMin;
	    int defuzzOperator = XfhlOperSet.DefuzOperatorFuzzyMean;
	    int IN_TYPE=XfhlInputType.FREE_TRIANGLES;
	    int AlgSelected = 0;
       
        XfghlConfig xfhlConfig = new XfghlConfig(nameSystem, numIterAjus, numThreads, fileDataSet, iniUpd, incFact, decFact, operatorAND, defuzzOperator, IN_TYPE, mfs, AlgSelected);
        System.out.println("configuracion creada");
        XfhlData data = new XfhlData(1, xfhlConfig.getnumIterAjust());
		EvaluationXfuzzy eval = new EvaluationXfuzzy(xfhlConfig);
		BufferedReader in = null;
		String filename = "configuration_7_restantes.txt";
		List<String> codificaciones = new ArrayList<String>();
		String codificacion = "";
		int evaluaciones = 1, index = 0;
		DoubleChromosome nuevo = null;
		try  {
			
			in = new BufferedReader(new FileReader(filename));
			codificacion = in.readLine();
			while (codificacion != null)  {
				codificaciones.add(codificacion);
				codificacion = in.readLine();
			}
			in.close();
			//File file = new File(filename);
			//file.delete();
			while ((index < evaluaciones) && (codificaciones.size() > 0))  {
				codificacion = codificaciones.remove(0);
				nuevo = new DoubleChromosome(xfhlConfig.getnumVarEnt(), codificacion);
				eval.evaluarIndividuo2(nuevo, new ResultGA());
				System.out.println(nuevo.getCodificacion() + " : " + nuevo.getFitness());
				index++;
			}
		}
		catch(Exception e)  {
			System.out.println(e.getMessage());
			e.printStackTrace();
		}
	}

}
